home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / bort22.zip / HOOK.QC < prev    next >
Text File  |  1996-10-09  |  8KB  |  257 lines

  1. //====================================================================
  2. //
  3. // GRAPPLING HOOK            by: Perecli Manole AKA Bort
  4. //
  5. //====================================================================
  6. // Aside from this new file, the following are the modifications
  7. // done to id's original source files:
  8. //--------------------------------------------------------------------
  9. // File: Progs.src
  10. // Location: before the "weapons.qc" line
  11. // Added: hook.qc
  12. //--------------------------------------------------------------------
  13. // File: Weapons.qc
  14. // Procedure: ImpulseCommands
  15. // Location: in the beginning of the function
  16. // Added: CheckGrapHook ();
  17. //--------------------------------------------------------------------
  18. // File: World.qc
  19. // Procedure: worldspawn
  20. // Location: after line "precache_model ("progs/s_spike.mdl");"
  21. // Added: precache_model ("progs/star.mdl");
  22. //        precache_model ("progs/bit.mdl");
  23. //--------------------------------------------------------------------
  24. // File: Weapons.qc
  25. // Procedure: W_Precache
  26. // Location: end of procedure
  27. // Added: precache_sound ("shambler/smack.wav");
  28. //        precache_sound ("blob/land1.wav");
  29. //--------------------------------------------------------------------
  30. // File: Defs.qc
  31. // Declaration group: player only fields
  32. // Location: after line ".float pain_finished;"
  33. // Added: .float hook;    
  34. //--------------------------------------------------------------------
  35. // File: Client.qc
  36. // Procedure: ClientConnect
  37. // Location: next line after bprint (" entered the game\n");
  38. // Added: centerprint("This server supports: ...bla.bla.bla..");
  39. //--------------------------------------------------------------------
  40.  
  41.  
  42. void(vector org, vector vel, float damage) SpawnBlood;    // prototype
  43. float () crandom;                               // prototype
  44.  
  45.  
  46. float    HOOK_OUT = 1;        // is hook currently extended? (bit flag)
  47. float    HOOK_ON = 2;        // is ACTIVE_HOOK impulse on? (bit flag)
  48. float ACTIVATE_HOOK = 98;    // impulse constant
  49. float    TERMINATE_HOOK = 97;    // impulse constant
  50.  
  51.  
  52. //--------------------------------------------------------------------
  53. // Disolves chain
  54. //--------------------------------------------------------------------
  55. void (entity Head) DisolveChain =
  56. {
  57.     local entity link;
  58.  
  59.     link = Head.goalentity;
  60.     while (link != world)
  61.     {
  62.         Head = link.goalentity;
  63.         remove (link);
  64.         link = Head;
  65.     }
  66. };
  67.  
  68.  
  69. //--------------------------------------------------------------------
  70. // Updated calculation of link positions
  71. //--------------------------------------------------------------------
  72. void () LinkPos =
  73. {
  74.     setorigin (self, self.owner.origin + ((self.enemy.origin + '0 0 16') - self.owner.origin) * self.weapon);
  75.     self.nextthink = time + 0.01;
  76. };
  77.  
  78.  
  79. //--------------------------------------------------------------------
  80. // Creates chain
  81. //--------------------------------------------------------------------
  82. entity (entity head, entity tail, float num) CreateChain =
  83. {
  84.     local entity link, prevlink;
  85.     local float linknum;
  86.  
  87.     linknum = num;
  88.     num = num + 1;
  89.     prevlink = world;
  90.     while (linknum > 0)
  91.     {
  92.         link = spawn();
  93.         link.goalentity = prevlink;
  94.         prevlink = link;
  95.         link.owner = head;
  96.         link.enemy = tail;
  97.         link.weapon = linknum / num;
  98.         link.movetype = MOVETYPE_NOCLIP;
  99.         link.solid = SOLID_NOT;
  100.         link.angles_z = 51 * linknum;
  101.         link.angles_y = 41 * linknum;
  102.         link.angles_x = 31 * linknum;
  103.         link.avelocity = '310 410 510';
  104.         setmodel (link, "progs/bit.mdl");
  105.         setsize (link, '0 0 0', '0 0 0');
  106.         setorigin (link, head.origin + ((tail.origin + '0 0 16') - head.origin) * link.weapon);
  107.         link.nextthink = time + 0.01;
  108.         link.think = LinkPos;
  109.         linknum = linknum - 1;
  110.     }
  111.     return link;
  112. };
  113.  
  114.  
  115. //--------------------------------------------------------------------
  116. // Removes star and detaches player
  117. //--------------------------------------------------------------------
  118. void () HookVanish =
  119. {
  120.     // removes flag of hook instance being present
  121.     self.owner.hook = self.owner.hook - (self.owner.hook & HOOK_OUT);
  122.         
  123.     DisolveChain (self);
  124.     remove (self);
  125. };
  126.  
  127.  
  128. //--------------------------------------------------------------------
  129. // Hook pulls player function
  130. //--------------------------------------------------------------------
  131. void () HookPull =
  132. {
  133.         local vector vel, spray;
  134.         local float v;
  135.  
  136.     if (     ((self.owner.hook & HOOK_ON) != HOOK_ON) || 
  137.         (self.owner.teleport_time > time) || 
  138.         (self.owner.deadflag) ||            // if player dies
  139.         (self.enemy.solid == SOLID_NOT)    )    // if target dies
  140.     {
  141.         HookVanish();
  142.         return;
  143.     }
  144.     
  145.     if (self.enemy.takedamage)
  146.         T_Damage (self.enemy, self, self.owner, 3);
  147.  
  148.     if (self.enemy.solid == SOLID_SLIDEBOX)
  149.     {
  150.         sound (self, CHAN_WEAPON, "blob/land1.wav", 1, ATTN_NORM);
  151.         spray_x = 100 * crandom();
  152.          spray_y = 100 * crandom();
  153.         spray_z = 100 * crandom() + 50;
  154.         SpawnBlood (self.origin, spray, 20);
  155.         setorigin (self, self.enemy.origin + self.enemy.mins + self.enemy.size * 0.5);
  156.     }
  157.  
  158.     self.velocity = self.enemy.velocity;
  159.         
  160.     vel = self.origin - (self.owner.origin + '0 0 16');
  161.     v = vlen (vel);
  162.     if (v <= 100)
  163.         vel = normalize(vel) * v * 7;  
  164.     if ( v > 100 )
  165.         vel = normalize(vel) * 700;  
  166.     self.owner.velocity = vel;
  167.     self.nextthink = time + 0.1;
  168. };
  169.  
  170.  
  171. //--------------------------------------------------------------------
  172. // Star's touch function
  173. //--------------------------------------------------------------------
  174. void() T_ChainTouch =
  175. {
  176.     if ((self.owner.hook & HOOK_ON) != HOOK_ON)
  177.     {
  178.         HookVanish();
  179.         return;
  180.     }
  181.  
  182.     if (other.takedamage)
  183.         T_Damage (other, self, self.owner, 10 );
  184.  
  185.      if (other.solid == SOLID_SLIDEBOX)
  186.     {
  187.         sound (self, CHAN_WEAPON, "shambler/smack.wav", 1, ATTN_NORM);    
  188.         SpawnBlood (self.origin, self.velocity, 10);
  189.         setorigin (self, other.origin + other.mins + other.size * 0.5);
  190.     }
  191.     else
  192.     {
  193.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  194.         self.avelocity = '0 0 0';
  195.     }
  196.  
  197.     self.velocity = other.velocity;
  198.  
  199.     self.enemy = other;
  200.     self.nextthink = time + 0.1;
  201.     self.think = HookPull;
  202.     self.touch = SUB_Null;
  203. };
  204.  
  205.  
  206. //--------------------------------------------------------------------
  207. // Shoots star
  208. //--------------------------------------------------------------------
  209. void(entity myself) W_FireChain =
  210. {
  211.     local entity star;
  212.  
  213.     star = spawn ();
  214.     star.owner = myself;
  215.     star.movetype = MOVETYPE_FLY;
  216.     star.solid = SOLID_BBOX;
  217.     setmodel (star, "progs/star.mdl");
  218.     setsize (star, '0 0 0', '0 0 0');     
  219.     makevectors (myself.v_angle);
  220.     setorigin (star, myself.origin + (v_forward*16) + '0 0 16' );
  221.     star.velocity = v_forward*1000;
  222.     star.angles = vectoangles(star.velocity);
  223.     star.avelocity = '0 0 600';
  224.     sound (myself, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  225.     
  226.     star.touch = T_ChainTouch;
  227.     star.nextthink = time + 0.7;     // reach length of grappling hook
  228.     star.think = HookVanish;
  229.     star.goalentity = CreateChain (star, myself, 8);
  230. };
  231.  
  232.  
  233. //--------------------------------------------------------------------
  234. // Checks impulse
  235. //--------------------------------------------------------------------
  236. void() CheckGrapHook = 
  237. {
  238.     if (((self.hook & HOOK_OUT) != HOOK_OUT) && (self.impulse == ACTIVATE_HOOK))
  239.     {
  240.         // flags that one instance of hook is spawned
  241.         self.hook = self.hook | HOOK_OUT;
  242.     
  243.         // flags last activated hook impulse as being ON 
  244.         self.hook = self.hook | HOOK_ON;   
  245.  
  246.         W_FireChain (self);
  247.         return;
  248.     }
  249.  
  250.     if (((self.hook & HOOK_OUT) == HOOK_OUT) && (self.impulse == TERMINATE_HOOK))
  251.     {
  252.         // flags last activated hook impulse as being OFF
  253.         self.hook = self.hook - (self.hook & HOOK_ON);
  254.         
  255.         return;
  256.     }
  257. };